package com.scuec.trainingmanagementsys.mapper;

import com.scuec.trainingmanagementsys.entity.Student;
import com.scuec.trainingmanagementsys.entity.Teacher;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface TeacherMapper {

    // 1. 整表查询
    @Select("SELECT * FROM teacher")
    List<Teacher> getAllTeachers();

    // 2. 根据工号查询
    @Select("SELECT * FROM teacher WHERE TeacherNumber = #{number}")
    Teacher getByNumber(@Param("number") String number);

    // 3. 根据姓名模糊查询
    @Select("SELECT * FROM teacher WHERE TeacherName LIKE CONCAT('%', #{name}, '%')")
    List<Teacher> searchByName(@Param("name") String name);

    // 4. 根据学院查询
    @Select("SELECT * FROM teacher WHERE College = #{college}")
    List<Teacher> getByCollege(@Param("college") String college);

    // 5. 姓名和学院多条件查询
    @Select("SELECT * FROM teacher " +
            "WHERE TeacherName LIKE CONCAT('%', #{name}, '%') " +
            "AND College = #{college}")
    List<Teacher> searchByNameAndCollege(@Param("name") String name, @Param("college") String college);

    // 6. 删除单条记录（按工号）
    @Delete("DELETE FROM teacher WHERE TeacherNumber = #{number}")
    int deleteByNumber(@Param("number") String number);

    // 7. 多选删除（按工号列表）
    @Delete("<script>" +
            "DELETE FROM teacher " +
            "WHERE TeacherNumber IN " +
            "<foreach collection='numbers' item='number' open='(' separator=',' close=')'>" +
            "#{number}" +
            "</foreach>" +
            "</script>")
    int deleteBatchByNumbers(@Param("numbers") List<String> numbers);

    // 8. 插入记录
    @Insert("INSERT INTO teacher (" +
            "TeacherNumber, TeacherName, College, Email, Phone, TeacherPassword) " +
            "VALUES (" +
            "#{teacher.teacherNumber}, #{teacher.teacherName}, #{teacher.college}, #{teacher.email}, #{teacher.phone}, #{teacher.teacherPassword})")
    int insertTeacher(@Param("teacher") Teacher teacher);

    // 9. 修改记录（按工号更新。不修改工号本身）
    @Update("UPDATE teacher " +
            "SET TeacherName = #{teacher.teacherName}, " +
            "College = #{teacher.college}, " +
            "Email = #{teacher.email}, " +
            "Phone = #{teacher.phone}, " +
            "TeacherPassword = #{teacher.teacherPassword} " +
            "WHERE TeacherNumber = #{teacher.teacherNumber}")
    int updateTeacher(@Param("teacher") Teacher teacher);

    // 根据工号和密码查询教师信息
    @Select("SELECT * FROM teacher WHERE TeacherNumber = #{number} AND TeacherPassword = #{password}")
    Teacher getByNumberAndPassword(@Param("number") String number, @Param("password") String password);

    // 统计教师总数
    @Select("SELECT COUNT(*) FROM teacher")
    int getTeacherCount();

    // 添加这个方法
    Teacher selectByNumberAndPassword(String teacherNumber, String password);

    @Select("SELECT teacherId FROM teacher WHERE teacherNumber = #{teacherNumber}")
    Integer getTeacherIdByNumber(String teacherNumber);

    // 根据教师编号查询教师信息
    // 添加 @Select 注解，直接定义 SQL
    @Select("SELECT TeacherID, TeacherNumber, TeacherName, College, Email, Phone, TeacherPassword " +
            "FROM teacher " +
            "WHERE TeacherNumber = #{teacherNumber}")
    Teacher findByTeacherNumber(String teacherNumber);

    @Select("SELECT * FROM teacher WHERE TeacherNumber = #{teacherNumber}")
    Teacher getTeacherProfile(String teacherNumber);


}